//控制单位放置UAV，并且绑上炸药出击
params ["_unit"];
if(side _unit == east) exitWith{};//红军不打

private["_assembled"];

if(typeOf _unit find "_UAV_" < 0
&& {typeOf _unit find "_UGV_" < 0}) exitWith{};


_assembled = getText (configfile >> "CfgVehicles" >> backpack _unit >> "assembleInfo" >> "assembleTo");

if(_assembled isEqualTo "")exitWith{};

                             
private _end = false;
while{!_end}do
{
	sleep 15;
	if((isNull _unit) || (!alive _unit)) exitWith {};
	
	if(simulationEnabled _unit) then{
		
		private _player = [_unit, 800] call fn_getPlayerAttack;
		
		if !(isNull _player) exitWith//这里似乎不能跳出循环
		{
			_end = true;
			[_unit,"AinvPknlMstpSnonWnonDnon_Putdown_AmovPknlMstpSnonWnonDnon"] remoteExec ["playMoveNow",0];
			sleep 5;
			private _veh = _assembled createvehicle (getPos _unit);
			_veh enableDynamicSimulation true;
			
			createVehicleCrew _veh;
			{
				[_x] joinSilent (group _unit);
			}forEach crew _veh;
			
			//
			_unit disableAI "MOVE";
			[_unit,"AmovPknlMstpSnonWnonDnon"] remoteExec ["switchMove",0];
			removeBackpackGlobal _unit;
			
			
			[_unit, _veh] spawn{
				params["_unit", "_veh"];
				if(!unitIsUAV _veh) exitWith{};
				//绑上炸弹
				private _exp = "SatchelCharge_Remote_Ammo" createVehicle position _veh;
				_exp attachTo [_veh, [0, 0, 0.15]];
				
				
				
				while{true}do{
					sleep 5;
					//单位死亡  无人机死亡 结束
					if(!alive _unit || !alive _veh) exitWith{doStop _veh;};
					
					//移动
					private _player = [_veh, 800] call fn_getPlayerAttack;
					
					if(!isNull _player) then{
						_veh engineOn true;
						_veh doMove position _player;
						
						//过近就飞低，退出逻辑锁定玩家
						if(_veh distance2D _player < 100)exitWith{
							_veh flyInHeight 1;
							
							[_unit, _veh,_player,_exp] spawn
							{
								params["_unit","_veh","_player", "_exp"];
								waitUntil{sleep 1;_veh doMove position _player; 
								!alive _unit || {!alive _veh} || {_veh distance _player < 8}};
								if(alive _unit || {!alive _veh}) then{
									_exp setDamage 1;
									_veh setDamage 1;
								};
								if(alive _unit) then{_unit enableAI "MOVE";};
							};
						};
					};
				};
			};
		};
	};
};
